from django.db import models
import uuid

# Create your models here.
"""
Django 数据库迁移命令: 
python manage.py makemigrations
python manage.py migrate
"""


# 年级
class pdf_grade(models.Model):
    name = models.CharField(verbose_name='等级名称', max_length=15, unique=True)
    create_time = models.DateTimeField(auto_now_add=True)


# pdf文件保存路径
class pdf_files_path(models.Model):
    pdf_id = models.CharField(primary_key=True, verbose_name='PDF文件ID', default=str(uuid.uuid4()), max_length=150)
    name = models.CharField(max_length=150, verbose_name='pdf名称', default='')
    pdf_file = models.FileField(upload_to='pdf_files/', verbose_name='pdf文件的保存路径')
    pdf_cover = models.FileField(upload_to='pdf_files/cover/', null=True, blank=True, verbose_name='pdf封面')
    grade = models.ManyToManyField(to=pdf_grade, verbose_name='等级')  # 多对多
    create_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'pdf_files_path'


# pdf分割下的img存储路径
class pdf_to_img_path(models.Model):
    pdf_id = models.ForeignKey(to='pdf_files_path', on_delete=models.CASCADE)
    img = models.FileField(upload_to='pdf_files/img_files/')
    text = models.TextField(verbose_name='图片文字', null=True, blank=True)
    create_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'pdf_to_img_path'